package com.audaque.springboot.foshanupload.web.mpjdemo.mpgt.controller;
import com.audaque.springboot.foshanupload.web.mpjdemo.mpgt.mapper.ActDefMapper;
import com.audaque.springboot.foshanupload.web.mpjdemo.mpgt.model.entity.ActNodeDef;

import java.util.List;
import com.audaque.springboot.foshanupload.core.result.R;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;


import com.audaque.springboot.foshanupload.web.mpjdemo.mpgt.service.IActDefService;
import com.audaque.springboot.foshanupload.web.mpjdemo.mpgt.model.entity.ActDef;
import com.audaque.springboot.foshanupload.web.mpjdemo.mpgt.model.req.ActDefReq;

import org.springframework.beans.factory.annotation.Autowired;



import io.swagger.annotations.*;


/**
 * <p>
 * 流程定义 前端控制器
 * </p>
 *
 * @author chinaben
 * @since 2023-04-07
 */
@RestController

@Api(value = "流程定义 前端控制器")

@RequestMapping("/actDef")
public class ActDefController {


    @Autowired
    private IActDefService iActDefService;

    @Autowired
    private ActDefMapper actDefMapper;


    private MPJLambdaWrapper<ActDef> mpjLambdaWrapper() {
        MPJLambdaWrapper<ActDef> mpjLambdaWrapper = new MPJLambdaWrapper<>();
        mpjLambdaWrapper
                .selectAll(ActDef.class)
                .selectCollection(ActNodeDef.class, ActDef::getActNodeDefList)
                .leftJoin(ActNodeDef.class, ActNodeDef::getActCode, ActDef::getActCode);
        return mpjLambdaWrapper;
    }




    @PostMapping(value = "/")
    @ApiOperation(value = "流程定义 分页查询")
    public R<Page<ActDef>> page(@RequestBody ActDefReq req) {
        Page<ActDef> page = actDefMapper.selectJoinPage(new Page<>(req.getPage(), req.getRows()), ActDef.class, this.mpjLambdaWrapper());
        return R.ok(page);
    }




    @PostMapping(value = "/list")
    @ApiOperation(value = "流程定义 列表查询")
    public R<List<ActDef>> list(@RequestBody ActDefReq req) {
        List<ActDef> list = actDefMapper.selectJoinList(ActDef.class, this.mpjLambdaWrapper());
        return R.ok(list);
    }





    @GetMapping(value = "/{id}")
     @ApiOperation(value = "流程定义 单体查询")
    public R<ActDef> getById(@PathVariable("id") String id) {
        ActDef one = actDefMapper.selectJoinOne(ActDef.class, this.mpjLambdaWrapper().eq(ActDef::getId, id));
        return R.ok(one);
    }

    @PostMapping(value = "/create")
     @ApiOperation(value = "流程定义 创建")
    public R<String> create(@RequestBody ActDef params) {
        iActDefService.save(params);
        return R.ok("创建成功");
    }
    @PostMapping(value = "/batchCreate")
     @ApiOperation(value = "流程定义 批量创建")
    public R<String> batchCreate(@RequestBody List<ActDef> params) {
        iActDefService.batchSave(params);
        return R.ok("创建成功");
    }

    @PostMapping(value = "/delete/{id}")
     @ApiOperation(value = "流程定义 删除")
    public R<String> delete(@PathVariable("id") String id) {
        iActDefService.removeById(id);
        return R.ok("删除成功");
    }

    @PostMapping(value = "/update")
     @ApiOperation(value = "流程定义 更新")
    public R<String> update(@RequestBody ActDef params) {
        iActDefService.updateById(params);
        return R.ok("更新成功");
    }
}
